//行政区划相关操作
import hainan from '/@/config/area/hainan'
import guangxi from '/@/config/area/guangxi'

interface BaseType{
    readonly PROVINCE_CODE: number
    readonly PROVINCE_NAME: number
    readonly CITY_CODE: number
    readonly CITY_NAME: number
    readonly AREA_CODE: number
    readonly AREA_NAME: number
    readonly areaData: Array<Object>
    getSingleInfo(orgcode: string, type: number):string
}

class Area implements BaseType{
    PROVINCE_CODE: number
    PROVINCE_NAME: number
    CITY_CODE: number
    CITY_NAME: number
    AREA_CODE: number
    AREA_NAME: number
    areaData: Array<Object>
    getSingleInfo(orgcode: string, type: number) {
        var area = ''
        if(orgcode.length >=7) {
            area = orgcode.substring(1,7)
        } else {
            area = orgcode
        }
        
        for (let i in this.areaData) {
            if (this.areaData[i]['areaCode'].indexOf(area) >= 0) {
                switch(type) {
                    case this.PROVINCE_CODE:
						return this.areaData[i]['provinceCode']
					case this.PROVINCE_NAME:
						return this.areaData[i]['provinceName']
                    case this.CITY_CODE:
                        return this.areaData[i]['cityCode']
                    case this.CITY_NAME:
                        return this.areaData[i]['cityName']
                    case this.AREA_CODE:
                        return this.areaData[i]['areaCode']
                    case this.AREA_NAME:
                        return this.areaData[i]['areaName']
					default:
						return '未知'
                }
            }
        }
    }

}

const area = new Area()
area.areaData = hainan.areaData
area.areaData = area.areaData.concat(guangxi.areaData)
area.PROVINCE_CODE= 1
area.PROVINCE_NAME= 2
area.CITY_CODE= 3
area.CITY_NAME= 4
area.AREA_CODE= 5
area.AREA_NAME= 6
export default area;